package moc.tds;

import java.util.ArrayList;
import java.util.HashMap;

import moc.type.ANYTYPE;
import moc.type.DTYPE;
import moc.type.object.*;

public class CLASSE implements DTYPE {
	
	public CLASSE(String ident,CLASSE mere, DESCRIPTEUR desc,
			HashMap<String, ATTRIBUTE> attributes) {
		super();
		this.mere = mere;
		this.desc = desc;
		this.attributes = attributes;
		this.ident =ident ;
	}
	private String ident ;
	
	public CLASSE(String ident,CLASSE mere){
		super() ;
		this.ident = ident ;
		this.mere = mere ;
	}

	public String getIdent() {
		return ident;
	}

	public void setIdent(String ident) {
		this.ident = ident;
	}
	private CLASSE mere ;
	public CLASSE getMere() {
		return mere;
	}

	public void setMere(CLASSE mere) {
		this.mere = mere;
	}

	public DESCRIPTEUR getDesc() {
		return desc;
	}

	public void setDesc(DESCRIPTEUR desc) {
		this.desc = desc;
	}

	public HashMap<String, ATTRIBUTE> getAttributes() {
		return attributes;
	}

	public void setAttributes(HashMap<String, ATTRIBUTE> attributes) {
		this.attributes = attributes;
	}


	private DESCRIPTEUR desc ;
    private HashMap<String,ATTRIBUTE> attributes ;	

	@Override
	public int getTaille() {
		// TODO Auto-generated method stub
		return 1;
	}

	@Override
	public boolean conforms(DTYPE autre) {
		
		return equals(autre);
	}

	@Override
	public boolean equals(DTYPE autre) {
		
		return ((autre instanceof CLASSE) &&((CLASSE)autre).ident.equals(ident))||autre instanceof ANYTYPE ;
	}

	
	public void addMeth(String id, INFOMETHODE info){
		this.desc.put(id, info) ;
	}
	public INFOMETHODE chercherMethode(String met){
		INFOMETHODE retour = this.desc.get(met+"_"+ident) ;
		if (retour == null&&mere!= null)  
			retour = this.desc.get(met+"_"+this.mere.ident) ;
		return retour ;
	}

	public int getAttribute(String att) {
		// TODO Auto-generated method stub
		return this.attributes.get(att).getDep();
	}

	public int getTailleAttributes() {
		int taille=0 ;
		for (ATTRIBUTE a : this.attributes.values()){
		taille += a.getTaille() ;	
		}
		return taille ;
	}
	
	public INFOMETHODE chercherMethodeLocale(String identc){
		
		return this.desc.get(identc+"_"+ident) ;
	}
	
	public void removeMth(String id){
		this.desc.remove(id+"_"+this.mere.ident) ;
	}
	
	public DESCRIPTEUR redefineMeth(String id){
		DESCRIPTEUR retour = new DESCRIPTEUR(this.desc.getEmp()) ;
		for(String s : this.desc.keySet()){
		
			if (s.equals(id+"_"+this.mere.ident)){
			
				retour.put(id+"_"+ident, this.desc.get(s)) ;
			}else{
				retour.put(s, this.desc.get(s)) ;
			}
		}
		return retour ;
	}
	
	public int getTailleMethodes(){
		return this.getDesc().size() ;
	}
}
